// 报错码
export const errorCodes = {
    "100": "未知错误",
    "101": "未实现",
    "102": "请求错误",
    "103": "密码错误",
    "104": "用户未找到",
    "105": "用户已存在",
    "106": "JWT生成错误",
    "107": "JWT销毁错误",
    "108": "token错误",
    "109": "用户信息错误",
    "110": "微信登录错误",
    "111": "微信解绑错误",
    "112": "数据库错误",
    "113": "Json解析错误",
    "114": "公司未找到",
    "115": "公司已存在",
    "116": "公司信息错误",
    "117": "电表未找到",
    "118": "权限错误",
    "119": "Gin对象错误",
    "120": "参数错误",
    "121": "密码错误",
    "200": "无错误"
}

// 引擎列表
export const engineList = [

    { value: 2, label: "大连思捷" },
    { value: 3, label: "迈德电子" },
    { value: 5, label: "迈硕电气" },
    { value: 11, label: "千汇压力表" },
    { value: 12, label: "迈硕-NBIOT" },
    { value: 14, label: "星纵" },
    { value: 15, label: '信驰48组' },
    { value: 16, label: '信驰机器人' },
    { value: 17, label: '贝泉' },
    { value: 18, label: '沂润' },
    { value: 8, label: "三普超声波" },
    { value: 9, label: "三宇" },
    { value: 10, label: "环网结构虚拟表" },
    { value: 7, label: "公式虚拟表" },
    { value: 1, label: "手动虚拟表" },
    { value: 19, label: "克隆虚拟表" }
];


export const symbolList = [
    { symbol: 'meter(x,START,END)', explanation: '获取id为x的表在start-end这段时间内的值。start和end填常量START和END,只用填表的id即可。', example: 'meter(147, START, END) = 10.7' },
    { symbol: '+', explanation: '加，plus', example: '1+2 = 3' },
    { symbol: '-', explanation: '减，sub', example: '8-3.5 = 4.5' },
    { symbol: '*', explanation: '乘，multiply', example: '2*3 = 6' },
    { symbol: '/', explanation: '除，division', example: '5/2 = 2.5' },
    { symbol: '%', explanation: '取余，remainder', example: '5%2 = 1' },
    { symbol: '^', explanation: '整数次方，integer power', example: '2^3 = 8, 3^2 = 9' },
    { symbol: 'e', explanation: '科学计数法，E-notation', example: '1.2e3 = 1.2e+3 = 1200，1.2e-2 = 0.012' },
    { symbol: '()', explanation: '括号，brackets', example: '(2+3)*4 = 20' },
    { symbol: '_', explanation: '数字分隔符，number separator', example: '123_456_789 = 123456789' },
    { symbol: 'pi', explanation: 'π', example: 'pi = 3.141592653589793' },
    { symbol: 'sin(x)', explanation: '正弦函数，sine', example: 'sin(pi/2) = 1' },
    { symbol: 'cos(x)', explanation: '余弦函数，cosine', example: 'cos(0) = 1' },
    { symbol: 'tan(x)', explanation: '正切函数，tangent', example: 'tan(pi/4) = 1' },
    { symbol: 'cot(x)', explanation: '余切函数，cotangent', example: 'cot(pi/4) = 1' },
    { symbol: 'sec(x)', explanation: '正割函数，secant', example: 'sec(0) = 1' },
    { symbol: 'csc(x)', explanation: '余割函数，cosecant', example: 'csc(pi/2) = 1' },
    { symbol: 'abs(x)', explanation: '绝对值，absolute value', example: 'abs(-6) = 6' },
    { symbol: 'ceil(x)', explanation: '向上取整', example: 'ceil(4.2) = 5' },
    { symbol: 'floor(x)', explanation: '向下取整', example: 'floor(4.8) = 4' },
    { symbol: 'round(x)', explanation: '四舍五入取整', example: 'round(4.4) = 4, round(4.5) = 5' },
    { symbol: 'sqrt(x)', explanation: '平方根，square root', example: 'sqrt(4) = abs(sqrt(4)) = 2' },
    { symbol: 'cbrt(x)', explanation: '立方根，cube root', example: 'cbrt(27) = 3' },
    { symbol: 'max(x, ...)', explanation: '参数中的较大值', example: 'max(1)=1,max(2,3)=3,max(4,8,6,8,10)=10' },
    { symbol: 'min(x, ...)', explanation: '参数中的较小值', example: 'min(1)=1,min(2,3)=2,max(4,8,6,8,10)=4' },
    { symbol: 'noerr(x)', explanation: '计算 x 出错时返回 0', example: 'noerr(1 / 1) = 1, noerr( 1/ 0 ) = 0' },
];

export const usageOptions = [
    { label: "用水日抄表", value: "用水日抄表" },
    { label: "用水日报表", value: "用水日报表" },
    { label: "用水月报表", value: "用水月报表" },
    { label: "电虚拟表", value: "电虚拟表" },
    { label: "气虚拟表", value: "气虚拟表" },
    { label: "水虚拟表", value: "水虚拟表" },
]

export const STANDARD_COAL_FACTORS = [
    // 燃料类
    { label: '原煤', value: 0.7143 },
    { label: '洗精煤', value: 0.9000 },
    { label: '洗中煤', value: 0.2857 },
    { label: '煤泥', value: 0.2857 }, // 范围：0.2857 ～ 0.4286
    { label: '煤矸石', value: 0.2857 }, // 用作能源
    { label: '焦炭', value: 0.9714 },
    { label: '煤焦油', value: 1.1429 },

    // 油类
    { label: '原油', value: 1.4286 },
    { label: '燃料油', value: 1.4286 },
    { label: '汽油', value: 1.4714 },
    { label: '煤油', value: 1.4714 },
    { label: '柴油', value: 1.4571 },

    // 气体燃料
    { label: '天然气', value: 1.1000 },
    { label: '液化天然气', value: 1.7572 },
    { label: '液化石油气', value: 1.7143 },
    { label: '炼厂干气', value: 1.5714 },
    { label: '焦炉煤气', value: 0.5714 },
    { label: '高炉煤气', value: 0.1286 },
    { label: '发生炉煤气', value: 0.1786 },
    { label: '重油催化裂解煤气', value: 0.6571 },
    { label: '重油热裂解煤气', value: 1.2143 },
    { label: '焦炭制气', value: 0.5571 },
    { label: '压力气化煤气', value: 0.5143 },
    { label: '水煤气', value: 0.3571 },
    { label: '粗苯', value: 1.4286 },
    { label: '甲醇(燃料)', value: 0.6794 },
    { label: '乙醇(燃料)', value: 0.9144 },
    { label: '氢气(燃料)', value: 0.3329 },
    { label: '沼气', value: 0.7143 }, // 范围：0.7143 ～ 0.8286

    // 电力和热力
    { label: '电力(当量值)', value: 0.1229 },
    { label: '热力(当量值)', value: 0.03412 },

    // 耗能工质
    { label: '新水', value: 0.2571 },
    { label: '软化水', value: 0.4857 },
    { label: '除氧水', value: 0.9714 },
    { label: '压缩空气', value: 0.0400 },
    { label: '氧气', value: 0.4000 },
    { label: '氮气(副产品)', value: 0.4000 },
    { label: '氮气(主产品)', value: 0.6714 },
    { label: '二氧化碳气', value: 0.2143 },
    { label: '乙炔', value: 8.3143 },
    { label: '电石', value: 2.0786 }
];

export const FIELD_CONFIG = {
    numPeople: {
        label: '单位人数',
        description: '用于计算年人均能源消耗指标，请输入单位实际使用办公场所的总人数（含正式工、外包等）'
    },
    area: {
        label: '单位面积',
        description: '用于计算年单位面积能源消耗指标，请输入单位实际使用的办公面积，单位：平方米'
    },
    energyCost: {
        label: '基准年能源成本',
        description: '用于计算系统节能效益，请输入未接入系统前最近一个完整年度的能源费用支出（含水电气等），单位：万元'
    },
    numBeds: {
        label: '床位数',
        description: '请输入单位实际使用的床位总数'
    }
}

// 事件类型定义
const EVENT_CATEGORIES = {
    TEST: '测试事件',
    DEVICE_FAULT: '设备故障',
    POWER_ABNORMAL: '用电异常',
    WATER_ABNORMAL: '用水异常',
    GAS_ABNORMAL: '用气异常',
    OIL_ABNORMAL: '用油异常',
    HEAT_ABNORMAL: '用热异常',
    CARBON_ABNORMAL: '碳排放异常',
    RESOURCE_ABNORMAL: '资源异常',
    USAGE_ABNORMAL: '用量异常'
}

// 严重等级定义
const SEVERITY_LEVELS = {
    CRITICAL: 1, // 严重
    WARNING: 2,  // 警告
    INFO: 3      // 提示
}

export const events = [
    {
        id: 0,
        name: "",
        category: "",
        subCategory: "",
        format: () => "",
        needs: [],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 1,
        name: "ETest",
        category: EVENT_CATEGORIES.TEST,
        subCategory: "测试事件",
        format: ({ meter_code }) => `测试事件 ${meter_code}`,
        needs: ['meter_code'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 2,
        name: "EUpdate",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "表状态更新",
        format: ({ meter_code, time, type }) => `${type}${meter_code}在${time}状态更新`,
        needs: ['meter_code', 'time', 'type'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 3,
        name: "EPersonChange",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "人为改变状态",
        format: ({ meter_code, time, type }) => `${type}${meter_code}在${time}状态被人为改变`,
        needs: ['meter_code', 'time', 'type'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 4,
        name: "EOverLimit",
        category: EVENT_CATEGORIES.POWER_ABNORMAL,
        subCategory: "过载(mindsIot设备)",
        format: ({ meter_code }) => `电表${meter_code}已过载`,
        needs: ['meter_code'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 5,
        name: "EOLRecovery",
        category: EVENT_CATEGORIES.POWER_ABNORMAL,
        subCategory: "过载恢复(mindsIot设备)",
        format: ({ meter_code }) => `电表${meter_code}过载已恢复`,
        needs: ['meter_code'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 6,
        name: "EOLTimed",
        category: EVENT_CATEGORIES.POWER_ABNORMAL,
        subCategory: "过载延迟断电(mindsIot设备)",
        format: ({ meter_code }) => `电表${meter_code}过载延迟断电`,
        needs: ['meter_code'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 7,
        name: "EOLImmediate",
        category: EVENT_CATEGORIES.POWER_ABNORMAL,
        subCategory: "过载立即断电(mindsIot设备)",
        format: ({ meter_code }) => `电表${meter_code}过载立即断电`,
        needs: ['meter_code'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 8,
        name: "EOLSRecovery",
        category: EVENT_CATEGORIES.POWER_ABNORMAL,
        subCategory: "过载延迟恢复(mindsIot设备)",
        format: ({ meter_code }) => `电表${meter_code}过载延迟恢复`,
        needs: ['meter_code'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 9,
        name: "ENoPower",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "掉电(mindsIot设备)",
        format: ({ meter_code, type }) => `${type}${meter_code}掉电`,
        needs: ['meter_code', 'type'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 10,
        name: "EPlanWaterOver",
        category: EVENT_CATEGORIES.WATER_ABNORMAL,
        subCategory: "水计划超标",
        format: ({ value_str }) => {
            if (!value_str) return "实际用水量已超出计划用量";
            const dates = value_str.split(' - ');
            const startDate = new Date(dates[0]);
            const endDate = new Date(dates[1]);
            const year = startDate.getFullYear();
            const month = startDate.getMonth() + 1;
            const startDay = startDate.getDate();
            const endDay = endDate.getDate();
            return `${year}年${month}月${startDay}日至${endDay}日期间的实际用水量已超出计划用量`;
        },
        needs: ['value_str'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 11,
        name: "EPlanElecOver",
        category: EVENT_CATEGORIES.POWER_ABNORMAL,
        subCategory: "电计划超标",
        format: ({ value_str }) => {
            if (!value_str) return "实际用电量已超出计划用量";
            const dates = value_str.split(' - ');
            const startDate = new Date(dates[0]);
            const endDate = new Date(dates[1]);

            const year = startDate.getFullYear();
            const month = startDate.getMonth() + 1;
            const startDay = startDate.getDate();
            const endDay = endDate.getDate();

            return `${year}年${month}月${startDay}日至${endDay}日期间的实际用电量已超出计划用量`;
        },
        needs: ['value_str'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 12,
        name: "EPlanGasOver",
        category: EVENT_CATEGORIES.GAS_ABNORMAL,
        subCategory: "气计划超标",
        format: ({ value_str }) => {
            if (!value_str) return "实际用气量已超出计划用量";
            const dates = value_str.split(' - ');
            const startDate = new Date(dates[0]);
            const endDate = new Date(dates[1]);

            const year = startDate.getFullYear();
            const month = startDate.getMonth() + 1;
            const startDay = startDate.getDate();
            const endDay = endDate.getDate();

            return `${year}年${month}月${startDay}日至${endDay}日期间的实际用气量已超出计划用量`;
        },
        needs: ['value_str'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 15,
        name: "EPlanCarbonOver",
        category: EVENT_CATEGORIES.CARBON_ABNORMAL,
        subCategory: "碳计划超标",
        format: ({ value_str }) => {
            if (!value_str) return "实际碳排放量已超出计划用量";
            const dates = value_str.split(' - ');
            const startDate = new Date(dates[0]);
            const endDate = new Date(dates[1]);

            const year = startDate.getFullYear();
            const month = startDate.getMonth() + 1;
            const startDay = startDate.getDate();
            const endDay = endDate.getDate();

            return `${year}年${month}月${startDay}日至${endDay}日期间的实际碳排放量已超出计划用量`;
        },
        needs: ['value_str'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 16,
        name: "EPlanPriceOver",
        category: EVENT_CATEGORIES.RESOURCE_ABNORMAL,
        subCategory: "价格计划超标",
        format: ({ value_str }) => {
            if (!value_str) return "实际价格已超出计划用量";
            const dates = value_str.split(' - ');
            const startDate = new Date(dates[0]);
            const endDate = new Date(dates[1]);

            const year = startDate.getFullYear();
            const month = startDate.getMonth() + 1;
            const startDay = startDate.getDate();
            const endDay = endDate.getDate();

            return `${year}年${month}月${startDay}日至${endDay}日期间的实际价格已超出计划用量`;
        },
        needs: ['value_str'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 17,
        name: "EElectricFault",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "电路故障-三普",
        format: ({ meter_code, time, type }) => `${type}${meter_code}在${time}发生电路故障`,
        needs: ['meter_code', 'time', 'type'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 18,
        name: "ESensorWarning",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "传感器警告-三普",
        format: ({ meter_code, time, type }) => `${type}${meter_code}在${time}传感器发出警告`,
        needs: ['meter_code', 'time', 'type'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 19,
        name: "ELeakageWaterAlarm",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "漏水告警-三普",
        format: ({ meter_code, time }) => `水表${meter_code}在${time}发生漏水`,
        needs: ['meter_code', 'time'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 20,
        name: "EReverseWarning",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "反向告警-三普",
        format: ({ meter_code, time }) => `水表${meter_code}在${time}出现反向流量`,
        needs: ['meter_code', 'time'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 21,
        name: "EAreaWaterDrained",
        category: EVENT_CATEGORIES.WATER_ABNORMAL,
        subCategory: "区域漏水",
        format: ({ area, value }) => `${area}区域可能存在漏水,预计漏水量为${value}m³`,
        needs: ['area', 'value'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 22,
        name: "EMainNetWaterDrained",
        category: EVENT_CATEGORIES.WATER_ABNORMAL,
        subCategory: "主网漏水",
        format: () => `主管网可能存在漏水`,
        needs: [],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 23,
        name: "EPlanUnknownWaterOver",
        category: EVENT_CATEGORIES.WATER_ABNORMAL,
        subCategory: "不明水率过高",
        format: () => `不明水率过高`,
        needs: [],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 24,
        name: "EUsageOver",
        category: EVENT_CATEGORIES.USAGE_ABNORMAL,
        subCategory: "用量异常",
        format: ({ meter_code, time, type }) => `${type}${meter_code}在${time}出现${type === "水表" ? "流量" : "用量"}异常`,
        needs: ['meter_code', 'time', 'type'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 25,
        name: "EMeterOffline",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "表离线",
        format: ({ meter_code, type }) => `${type}${meter_code}已离线`,
        needs: ['meter_code', 'type'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    },
    {
        id: 26,
        name: "EMeterLongTimeOffline",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "表长时间离线",
        format: ({ meter_code, type }) => `${type}${meter_code}长期离线，请检查设备运行情况`,
        needs: ['meter_code', 'type'],
        defaultSeverity: SEVERITY_LEVELS.CRITICAL
    },
    {
        id: 27,
        name: "EMeterLowBattery",
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: "表电量低",
        format: ({ meter_code, type }) => `${type}${meter_code}电量低`,
        needs: ['meter_code', 'type'],
        defaultSeverity: SEVERITY_LEVELS.INFO
    },
    {
        id: 28,
        name: 'EMagnetism',
        category: EVENT_CATEGORIES.DEVICE_FAULT,
        subCategory: '磁性异常',
        format: ({ meter_code, time, type }) => `${type}${meter_code}在${time}发生磁性异常`,
        needs: ['meter_code', 'time', 'type'],
        defaultSeverity: SEVERITY_LEVELS.WARNING
    }
]

// 导出严重等级
export const SEVERITY = SEVERITY_LEVELS;

export const categoryMap = {
    '自定义': [],
    '通用': ['生活用水', '办公用水', '绿化用水', '消防用水', '特殊功能用水', '冷却塔用水'],
    '农业': ['灌溉用水'],
    '工业': ['生产用水', '冷却塔用水'],
    '医院': ['生活用水', '医疗用水', '特殊用水',],
    '学校': ['生活用水', '教学办公用水', '食堂用水', '绿化及景观用水', '体育场馆用水'],
    '服务业': ['食堂', '绿化', '空调系统', '洗涤', '净水', '洗浴', '娱乐', '造雪', '实验设备', '其他'],
};

export const meterTypeMap = {
    water: [
        { value: "自来水", label: "自来水" },
        { value: "地下水", label: "地下水" },
        { value: "地表水", label: "地表水" }
    ],
    elec: [
        { value: "商业用电", label: "商业用电" },
        { value: "工业用电", label: "工业用电" },
        { value: "生活用电", label: "生活用电" }
    ],
    gas: [
        { value: "商业用气", label: "商业用气" },
        { value: "工业用气", label: "工业用气" },
        { value: "生活用气", label: "生活用气" }
    ],
}